package org.jet.emall.rbac.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.jet.emall.common.restful.result.CommonResult;
import org.jet.emall.rbac.annotation.ApiInformation;
import org.jet.emall.rbac.dto.AdminMenuDTO;
import org.jet.emall.rbac.service.CustomAdminMenuService;
import org.jet.emall.rbac.transfer.AdminMenuVoTransfer;
import org.jet.emall.rbac.vo.AdminMenuVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiaozai
 * @version 1.0
 * @date 2020-04-05 16:46
 */
@Api(value = "管理员菜单控制器")
@RestController
public class AdminMenuController {

    @Autowired
    private CustomAdminMenuService customAdminMenuService;

    @ApiInformation(function = "加载菜单")
    @ApiOperation(value = "获取菜单树")
    @RequestMapping(value = "/menus",method = RequestMethod.GET)
    public CommonResult<List<AdminMenuVO>> list(@RequestAttribute Integer roleId){
        List<AdminMenuDTO> dtoList = customAdminMenuService.list(roleId);
        List<AdminMenuVO> voList = AdminMenuVoTransfer.INSTANCE.toVoList(dtoList);
        return CommonResult.success(voList);
    }
}
